package efrei.ngo.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;

public class GeneralUnil {
	public static String changeDateToString(GregorianCalendar dateIn) {
		return dateIn.get(GregorianCalendar.YEAR) + "-"
				+ dateIn.get(GregorianCalendar.MONTH) + "-"
				+ dateIn.get(GregorianCalendar.DATE);
	}
	
	public static GregorianCalendar changeDateToGregorianCalendar(Date cDate){
		GregorianCalendar   gDate   =   new   GregorianCalendar();
		gDate.setTime(new   Date());
		return gDate;
	}
	
	public static String getCountryListHTML(String strID){
		String countryHTML="<select name='"+strID+"' id='"+strID+"'>";
		ArrayList<String> cList;
		
		DatabaseAccess.connectToDB();
		countryHTML+="<option value=''>----</option>";
		cList=DatabaseAccess.dbGetCountryListViaContinent("Africa");
        countryHTML+="<optgroup label='Africa'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
        countryHTML+="</optgroup>";
        
        cList=DatabaseAccess.dbGetCountryListViaContinent("Asia");
        countryHTML+="<optgroup label='Asia'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
        countryHTML+="</optgroup>";
        
        cList=DatabaseAccess.dbGetCountryListViaContinent("Europe");
        countryHTML+="<optgroup label='Europe'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
        countryHTML+="</optgroup>";
        
        cList=DatabaseAccess.dbGetCountryListViaContinent("North America");
        countryHTML+="<optgroup label='North America'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
        countryHTML+="</optgroup>";
        
        cList=DatabaseAccess.dbGetCountryListViaContinent("Oceania");
        countryHTML+="<optgroup label='Oceania'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
        countryHTML+="</optgroup>";
        
        cList=DatabaseAccess.dbGetCountryListViaContinent("South America");
        countryHTML+="<optgroup label='South America'>";
    	for(int i=0,len=cList.size();i<len;i++){
    		countryHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}
    	countryHTML+="</optgroup></select>";
    	
    	DatabaseAccess.endConnectionToDB();
    	
    	return countryHTML;
	}

	public static String getTypeListHTML(String strID){
		String typeHTML="<select name='"+strID+"' id='"+strID+"'>";
		ArrayList<String> cList;
		
		DatabaseAccess.connectToDB();
		typeHTML+="<option value=''>----</option>";
		cList=DatabaseAccess.dbGetTypeList();
    	for(int i=0,len=cList.size();i<len;i++){
    		typeHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}	
    	typeHTML+="</select>";
    	DatabaseAccess.endConnectionToDB();
    	
    	return typeHTML;
	}
	
	public static String getContinentListHTML(String strID){
		String typeHTML="<select name='"+strID+"' id='"+strID+"'>";
		ArrayList<String> cList;
		
		DatabaseAccess.connectToDB();
		typeHTML+="<option value=''>----</option>";
		cList=DatabaseAccess.dbGetContinentList();
    	for(int i=0,len=cList.size();i<len;i++){
    		typeHTML+="<option value='"+cList.get(i)+"'>"+cList.get(i)+"</option>";
    	}	
    	typeHTML+="</select>";
    	DatabaseAccess.endConnectionToDB();
    	
    	return typeHTML;
	}
}
